from time import sleep
import uiautomation
import pyautogui
class feiyongbulu():
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()
        feiyongbuluchuangkou = his.WindowControl(ClassName='Window',Name='费用补录')
        shurukuang  = feiyongbuluchuangkou.EditControl(ClassName='TextBox')
        dingwei = feiyongbuluchuangkou.ButtonControl(AutomationId='btnQuery',ClassName='Button',Name='定位')
        tijiao = feiyongbuluchuangkou.ButtonControl(AutomationId='btnTJ',ClassName='Button',Name='提交')
        zhancun  = feiyongbuluchuangkou.ButtonControl(AutomationId='btnZC',ClassName='Button',Name='暂存')

        #数据网格
        shujuwangge = feiyongbuluchuangkou.DataGridControl(AutomationId='dgMedInput',ClassName='YDataGrid')
                #选择最后一条数据

        def choose_last_xmmc(self,name):
                last_sj = self.shujuwangge.GetLastChildControl()
                last_sj1 = last_sj.GetFirstChildControl()
                while True:
                        if last_sj1.Name != '项: Yuanbo.ChssClient.CommonManagement.Model.ZhuYuanFeiYongBuLuModel，列显示索引: 3':
                                last_sj1 = last_sj1.GetNextSiblingControl()
                                pass
                        else:
                                last_sj1.DoubleClick()
                                pyautogui.hotkey('ctrl', 'a')
                                pyautogui.hotkey('back')
                                last_sj1.GetFirstChildControl().SendKeys(name)
                                pyautogui.press('enter')
                                break


        #冲减数量确认菜单
        chongjianshuliangquerencaidan = feiyongbuluchuangkou.WindowControl(ClassName='Window',Name='冲减数量确认')
        cj_queding = chongjianshuliangquerencaidan.ButtonControl(AutomationId='btnSave',ClassName='Button',Name='确定')
        #点击确定
        def click_cjqd(self):
                self.chongjianshuliangquerencaidan.Refind()
                self.cj_queding.Refind()
                self.cj_queding.Click()
                sleep(2)
        #右键菜单
        caidan = his.MenuControl(ClassName='ContextMenu')
        zengjia = caidan.MenuItemControl(ClassName='MenuItem', Name='增加')
        fuzhi = caidan.MenuItemControl(ClassName='MenuItem', Name='复制')
        shanchu = caidan.MenuItemControl(ClassName='MenuItem', Name='删除')
        chongjian = caidan.MenuItemControl(ClassName='MenuItem', Name='冲减')
        #点击增加收费项目
        def add_sfxm(self, num: int):
                for i in range(num):
                        uiautomation.RightClick(779,677)
                        self.zengjia.Click()
                        pyautogui.scroll(clicks=-30)
        #点击冲减最后一条数据
        def clik_cj_last(self):
                self.shujuwangge.GetLastChildControl().RightClick()
                self.chongjian.Click()
        #点击冲减第一条数据
        def clik_cj_first(self):
                self.shujuwangge.GetFirstChildControl().GetNextSiblingControl().RightClick()
                self.chongjian.Click()




        #输入框输入
        def input_xmmc(self,name):
                self.shurukuang.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.shurukuang.SendKeys(name)
        #点击定位
        def click_dw_btn(self):
                self.dingwei.Click()
        #点击暂存
        def click_zc_btn(self):
                self.zhancun.Click()
        #点击提交
        def click_tj_btn(self):
                self.tijiao.Click()
        #关闭窗口
        def close_window(self):
                self.feiyongbuluchuangkou.Refind()
                self.feiyongbuluchuangkou.GetWindowPattern().Close()




